
<%
	if (session.getAttribute("username") == null) {
		%><jsp:forward page="login.jsp" /><%
	}
%>
<%@ page language="java" contentType="text/html; charset=GBK"  
    pageEncoding="GBK" import="java.sql.*, connection.*"%>  

<%
String pollid = (String)session.getAttribute("pollid");
String pollname = (String)session.getAttribute("pollname");
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">  
<html>  
<head>  
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<link href="/DBP/style/stylesheet.css" rel="stylesheet" type="text/css" />  
<title>PollMaster: Assign User</title>  
<script type="text/javascript" >
function showUser(){
	document.getElementById("username").style.display = "block";
	document.getElementById("list").style.display = "none";
}

function showList(){
	document.getElementById("list").style.display = "block";
	document.getElementById("username").style.display = "none";
}
</script>
</head>
<body>
<div id="write"></div>
<div class="bg">
<div class="content">
<jsp:include page="../nav.jsp" />
<br/>
	<div class="entrytitle">
	Assign Users to <%=pollname %>
	<div class="entry">
			
			<input type="radio" value="user" onClick="javascript:showUser()" name="userOrList"/>Single User<br/>
			<input type="radio" value="list" onClick="javascript:showList()" name="userOrList"/>Participant List
				<span id="username" style="display:none;"><br/>
					<form action="AssignUserServlet?type=single" method="post"">
						<label for="username">Username</label><br/><input type="text" name="username" id="username"/>
						<input type="submit" class="button" value="Assign User"/>
					</form>
				</span>
			
				<span id="list" style="display:none;">
				<form action="AssignUserServlet?type=single" method="post"">
					<br/><label for="participantlist">Select Participant List</label><br/>
					<select name="participantlist" id="participantlist">
						<%
						Connection conn = new DbConnection().getConn();
						String sql = "SELECT DISTINCT ListID, MasterUsername, Name FROM ParticipantList WHERE ParticipantList.MasterUsername='";
						sql+=(String)session.getAttribute("username")+"'";
						System.out.println(sql);
						try{
							PreparedStatement ps = conn.prepareStatement(sql);
							ResultSet rs = ps.executeQuery();
							
							while(rs.next()){
								String id = rs.getString("ListID");
								String name = rs.getString("name");
								
								out.write("<option value=\" ");
								out.write(id+","+name);
								out.write(" \">"+name+"</option>");
							}
						}catch(SQLException e){
							System.out.println(e.toString());
							e.printStackTrace();
						}
						%>
					</select><br/>
					<input type="submit" class="button" value="Assign List"/>
				</form>
				</span>
				
			</div>
			</div>
			</div>
</div>
</body>  
</html>  
